package de.uni_saarland.coli.doclists.data.btree;

import de.uni_saarland.coli.doclists.index.filesystem.IToBytes;

/**
 * 
 * @author stefan
 * 
 *         Inteface of B-Tree nodes.
 * 
 * @param <T>
 *            The type of data.
 */
public interface INode<T> extends IToBytes {
	int getNodeID();
	/**
	 * Returns if node is a bucket
	 * 
	 * @return ture if this is a bucket otherwise false
	 */
	boolean isBucket();

	/**
	 * Returns if node is not a bucket
	 * 
	 * @return ture if this is not a bucket otherwise false
	 */
	boolean isNotBucket();

	/**
	 * Is the node full
	 * 
	 * @return true if the node is full otherwise false
	 */
	boolean isFull();

	/**
	 * Splits the node in the midlle
	 * 
	 * @return a <code>SplitData</code> objects
	 */
	SplitData<T> split();

	/**
	 * Adds data to the node
	 * 
	 * @param key
	 *            a <code>int</code>: the key
	 * @param value
	 *            a <code>T</code>: the value
	 * @return a <code>SplitData</code> object containing the result of the
	 *         splitting otherwise null
	 */
	SplitData<T> addData(int key, T value);

	/**
	 * Returns the value of a key
	 * 
	 * @param key
	 *            key a <code>int</code>: the key
	 * @return a <code>T</code>: the value
	 */
	T get(int key);

	/**
	 * Returns the index of a link given a key.
	 * 
	 * @param key
	 *            a <code>int</code>: the key
	 * @return a <code>int</code>: the index of the link
	 */
	int findLink(int key);

	/**
	 * Shifts the keys one to the left starting at the index
	 * 
	 * @param idx
	 *            a <code>int</code>: the index of the link
	 */
	void shiftKeysLeft(int idx);

	/**
	 * Fills the buffer with the text, given a delimiter
	 * 
	 * @param delim
	 * @param sb
	 */
	void toStingHelper(String delim, StringBuilder sb);
}
